package interview.Algorithms;

import java.util.ArrayList;
import java.util.Iterator;

class Edge implements Comparable<Edge>{
	private int u;
	private int v;
	private int weight;
	private boolean visited;

	public Edge (int u, int v , int weight){
		this.u =u;
		this.v=v ;
		this.weight = weight;				
	}
	
	public int getU() {
		return u;
	}

	public int getV() {
		return v;
	}
	
	public boolean isVisited() {
		return visited;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	public int getAnotherVertex(int vertex){
		if (vertex == u) return v;
		return u;
	}

	public int getWeight() {
		return weight;
	}
	
	public String toString(){
		return ""+u+"--"+v+"-->"+weight;
	}
	
	public int compareTo(Edge that) {
		if(that==null) return -1;
		if (this==that) return 0;
		if (weight > that.weight) return 1 ;
		else if(weight < that.weight) return -1;
		else return 0;
	}
}

class Vertex{
	private ArrayList<Edge> connectedVertices = new ArrayList<Edge>();
	public void addEdge(Edge e){
		connectedVertices.add(e);
	}
	public Iterator<Edge> getEdges(){
		return connectedVertices.iterator();
	}
}

class Graph{
	private Vertex[] adjacencyList ;
	private int edges;
	private int vertices;
	
	public Graph(int vertices){
		adjacencyList = new Vertex[vertices+1];	
		this.vertices = vertices+1;
		for(int i=0;i<adjacencyList.length;i++)
			adjacencyList[i]=new Vertex();
	}
	public void addEdge(Edge e){
		edges++;
		adjacencyList[e.getU()].addEdge(e);
		adjacencyList[e.getV()].addEdge(e);
	}
	
	public int getVertices() {
		return vertices;
	}
	public int getEdges() {
		return edges;
	}
	public Vertex getVertexInfo(int vertex){
		return adjacencyList[vertex];
	}
	
}

class Generics {

}
